package com.wanglei.controller;

import com.wanglei.domain.ResponseResult;
import com.wanglei.domain.dto.AddArticleDto;
import com.wanglei.domain.entity.ArticleDetail;
import com.wanglei.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto article){
        return articleService.add(article);
    }

    @GetMapping("/list")
    public ResponseResult list(Integer pageNum ,Integer pageSize ,String title ,String summary){
        return articleService.list(pageNum,pageSize,title,summary);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticleDetailById(@PathVariable Long id){
        return articleService.getArticleDetailById(id);
    }

    @PutMapping
    public ResponseResult updateArticle(@RequestBody ArticleDetail articleDetail){
        return articleService.updateArticle(articleDetail);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteArticle(@PathVariable Long id){
        return articleService.deleteArticle(id);
    }

}
